package com.asion.qkan.ui.model;

import com.asion.qkan.api.ServiceApi;
import com.asion.qkan.entry.NewBean;
import com.asion.qkan.ui.contract.SheQuNewContract;
import com.asion.qkan.utils.retrofitCache.SetCacheUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/10/17 0017.
 */

public class SheQuNewModel implements SheQuNewContract.Model {
    @Override
    public void getSheNewQuListDatas(int type, SheQuNewContract.OnSheQuNewGetListener onSheQuGetListener) {
        new Retrofit.Builder().baseUrl("http://api.kkmh.com/")
                .client(SetCacheUtils.setCache())
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(ServiceApi.class)
                .getNewCommend(type)
                .enqueue(new Callback<NewBean>() {
                    @Override
                    public void onResponse(Call<NewBean> call, Response<NewBean> response) {
                        NewBean body = response.body();
                        onSheQuGetListener.onSheQuSuccess(body.getData());
                    }

                    @Override
                    public void onFailure(Call<NewBean> call, Throwable t) {
                        onSheQuGetListener.onSheQuError(t);
                    }
                });
    }
}
